#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>

#define NUM_SUPPLY 10
void testGHallEffect (void)
{
    struct gameState G;
    int k[NUM_SUPPLY] =
    {
        adventurer, gardens, embargo, great_hall, minion, mine, cutpurse,
        sea_hag, tribute, smithy
    };
    
    initializeGame(2, k, 1, &G);
    
    int player = G.whoseTurn;
    
    int ghall_pos = G.handCount[player];
    
    if (gainCard (great_hall, &G, 2, player) == -1)
    {
        printf ("%s: FAIL attempting to gain a great hall!\n", __func__);
        return;
    }
    else
    {
        printf ("%s: PASS attempting to gain a great hall.\n", __func__);
    }
    
    if (cardEffect (great_hall, 0, 0, 0, &G, ghall_pos, NULL) == -1)
    {
        printf ("%s: FAIL attempting to play a great hall!\n", __func__);
        return;
    }
    else
    {
        printf ("%s: PASS attempting to play a great hall.\n", __func__);
    }
    
    if (G.handCount[player] == ghall_pos + 1)
    {
        printf ("%s: PASS verifying great hall drew 1 card.\n", __func__);
    }
    else
    {
        printf ("%s: FAIL verifying great hall drew 1 card (%d != 1!)\n", __func__, G.handCount[player] - ghall_pos);
        return;
    }
    
    for (int i = 0; i < G.handCount[player]; i++)
    {
        char *ordinals[3] = {"first", "second", "third"};
        int card = G.hand[player][i];
        if (card != copper && card != estate)
        {
            printf ("%s: FAIL verifying %s card drawn by great hall is valid (%d is not!)\n", __func__, ordinals[i-ghall_pos], card);
            return;
        }
    }
    
    printf ("%s: PASS verifying all cards drawn by great hall are valid.\n", __func__);
    
    if (G.numActions == 2)
        printf ("%s: PASS verifying great hall added one action.\n", __func__);
    else
        printf ("%s: FAIL verifying great hall added one action (%d != 2!)\n", __func__, G.numActions);
}

int main (int argc, char *argv[])
{
    testGHallEffect ();
}
